<style>
    .el-table th, .el-table td .el-input--mini.align-right .el-input__inner{text-align:right;}
</style>
<template>
    <div class="change-plan-page">
        <!--
        <router-link to="/SparePlan" style="float: right">
            <el-button type="danger" icon="close" size="mini" class="bolder outsideBtnBS"></el-button>
        </router-link>
         
        <div class="block" style="margin-bottom: 10px">
            <span class="wrapper">
                <el-button type="danger" size="mini" class="bolder outsideBtnBS" style="margin-left:0!important;" @click="savePlan">保存</el-button>
                <el-button type="danger" size="mini" class="bolder outsideBtnBS" @click="submitPlan">提交</el-button>
                <el-button type="danger" size="mini" class="bolder outsideBtnBS" @click="handleReview">审核</el-button>
                <el-button type="danger" size="mini" class="bolder outsideBtnBS" @click="handleApprove">审批</el-button>
            </span>
        </div>
        -->
        <el-form :inline="true" :model="modifyForm" ref="modifyForm" style="margin-bottom:20px;border-bottom:1px solid #ccc;">
            <el-form-item label="计划编号:" class="selectMB10">
                <el-input size="mini" disabled placeholder="" v-model="modifyForm.planCode"></el-input>
            </el-form-item>
            <el-form-item label="制定人:" class="selectMB10">
                <el-input size="mini" disabled v-model="modifyForm.creatorName"></el-input>
            </el-form-item>
            <el-form-item label="制定时间:" class="selectMB10">
                <el-input size="mini" disabled v-model="modifyForm.createTime"></el-input>
            </el-form-item>
            <el-form-item label="法人名称:" class="selectMB10" prop="legalPersonName" :rules="[{ required: true, message: '法人名称不能为空'}]">
                 <el-select size="mini" v-model="modifyForm.legalPersonName" disabled  @change="selectLegalPersonName" placeholder="请选择">
                    <el-option v-for="(legalPerson,index) in legalPersonLists" :key="index" :label="legalPerson.legalPersonName" :value="legalPerson.legalPersonName">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="计划来源:" class="selectMB10" prop="source" :rules="[{ required: true, message: '计划来源不能为空'}]">
                <el-select size="mini" v-model="modifyForm.source" disabled placeholder="请选择">
                    <el-option v-for="(source,index) in sourceLists" :key="index" :label="source.label" :value="source.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="计划币别:" class="selectMB10" prop="currencyCode" :rules="[{ required: true, message: '计划币别不能为空'}]">
                <el-select size="mini" v-model="modifyForm.currencyCode" disabled placeholder="请选择" @change="selectCurrencyCode">
                    <el-option v-for="(currencyCode,index) in currencyCodeLists" :key="index" :label="currencyCode.label" :value="currencyCode.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="计划总件数:" class="selectMB10">
                <el-input size="mini" disabled v-model="modifyForm.totalCount"></el-input>
            </el-form-item>
            <el-form-item label="计划总金额:" class="selectMB10">
                <el-input size="mini" disabled v-model="modifyForm.total"></el-input>
            </el-form-item>
            <el-form-item class="selectMB10">
                <el-button v-if="modifyForm.status==1" type="danger" size="mini" class="bolder outsideBtnBS" style="margin-left:0!important;" @click="savePlan">保存</el-button>
                <el-button v-if="modifyForm.status==1" type="danger" size="mini" class="bolder outsideBtnBS" @click="submitPlan">提交</el-button>
                <!-- 
                <el-button v-if="modifyForm.status==2" type="danger" size="mini" class="bolder outsideBtnBS" @click="handleReview">审核</el-button>
                <el-button v-if="modifyForm.status==3" type="danger" size="mini" class="bolder outsideBtnBS" @click="handleApprove">审批</el-button>
                -->
            </el-form-item>
        </el-form>
        <el-form :inline="true" ref="form" :model="modifyDetail">
            <el-form-item label="备件编码">
                <el-input size="mini" v-model="modifyDetail.materialCode"></el-input>
            </el-form-item>
            <el-form-item label="备件分类:">
                <el-select v-model="modifyDetail.materialSubclass" placeholder="请选择" clearable>
                    <el-option v-for="(materialSubclass,index) in materialSubclassLists" :key="index" :label="materialSubclass" :value="materialSubclass">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="danger" size="mini" class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" @click="checkTheDetails()">查询</el-button>
                <!--新增按钮pageIndex,pageSize-->
                <el-button type="danger" size="mini" class="bolder outsideBtnBS" @click="modifyFormDetais(sparePageIndex,sparePageSize)">新增</el-button>
            </el-form-item>
        </el-form>
        <!--表格-->
        <el-table :data="tableData" border style="width: 100%">
            <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
            <el-table-column label="操作"  width="100" align="center">
                <template scope="scope">
                    <div class="operationItem bolder" @click="handleDelete(scope.$index, scope.row)">删除</div>
                </template>
            </el-table-column>
            <el-table-column prop="materialSubclass" label="分类"  width="60" header-align="center" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="materialCode" label="备件编码"   header-align="center" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="materialName" label="备件名称"  header-align="center" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="standard" label="规格"  width="60" header-align="center" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="unit" label="计量单位"  width="80" header-align="center" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="quantity" label="计划数量"  width="80" header-align="center">
                <template scope="scope">
                    <el-input size="mini"  v-model.number="scope.row.quantity" placeholder="请输入" @change="planQuantity(scope.$index, scope.row,$event)"></el-input>
                </template>
            </el-table-column>
            <el-table-column prop="currencyCodeWord" label="币别"  width="60" header-align="center" show-overflow-tooltip> </el-table-column>
            <el-table-column prop="price" label="单价" header-align="center" align="right">
                <template scope="scope">
                    <el-input size="mini"  v-model.number="scope.row.price" placeholder="请输入" @change="planPrice(scope.$index, scope.row,$event)" class="align-right"></el-input>
                </template>
            </el-table-column>
            <el-table-column prop="amount" label="金额" header-align="center" align="right"> </el-table-column>
            <el-table-column prop="deliveryTimeExpectation" label="期望到货时间"  header-align="center" width="200">
                <template scope="scope">
                    <el-date-picker type="date" size="mini" :editable="false" v-model="scope.row.deliveryTimeExpectation"  placeholder="请选择期望到货时间" :picker-options="pickerOptions" @change="selectedDeliveryTimeExpectation(scope.$index,scope.row)"></el-date-picker>
                </template>
            </el-table-column>
            <el-table-column prop="remark" label="备注"  header-align="center" show-overflow-tooltip>
                <template scope="scope">
                    <el-input size="mini"  v-model.number="scope.row.remark" placeholder="请输入"></el-input>
                </template>
            </el-table-column>
        </el-table>
        <!--新增弹窗-->
        <el-dialog title="选择备件" :visible.sync="dialogFormVisible" :lock-scroll="false">
            <el-form :model="chooseSpare" :inline="true">
                <el-form-item label="备件编号:" >
                    <el-input size="mini" v-model="chooseSpare.code" auto-complete="off" placeholder="请输入备件编号"></el-input>
                </el-form-item>
                <el-form-item label="备件名称:" >
                    <el-input size="mini" v-model="chooseSpare.name" auto-complete="off" placeholder="请输入备件名称"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="danger" class="bolder outsideBtnBS selectAll" :disabled="select2Disabled" size="mini" @click="modifyFormDetais(sparePageIndex,sparePageSize)">查询</el-button>
                    <el-button type="danger" class="bolder outsideBtnBS" size="mini" @click="insertMateraialSupplier">确定</el-button>
                </el-form-item>
            </el-form>
            <el-table :data="spareListDate" border style="margin-top:16px;width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
                <el-table-column type="index" header-align="center" align="center" label="序"  width="40"></el-table-column>
                <el-table-column label="选择" header-align="center" align="center" width="40">
                    <template scope="scope">
                        <el-checkbox size="mini" v-model="scope.row.checked" @change="selectSpare(scope.$index, scope.row)"></el-checkbox>
                    </template>
                </el-table-column>
                <el-table-column prop="code" label="备件编号" header-align="center" show-overflow-tooltip></el-table-column>
                <el-table-column prop="name" label="编码名称" header-align="center" show-overflow-tooltip></el-table-column>
            </el-table>
            <!--分页-->
            <el-pagination v-if="isPagingSpare" @size-change="spareSizeChange" @current-change="spareCurrentChange"  :current-page.sync="spareCurrentPage3" :current-page="sparePageIndex"   :page-sizes="[5, 10, 15 , 20, 25]" :page-size="sparePageSize" layout="total, sizes, prev, pager, next, jumper" :page-count="spareTotalPage" :total="spareTotalNumber"></el-pagination>
        
        </el-dialog>

        <!-- 点击审核 审核弹窗 
        <el-dialog title="审核提示信息" :visible.sync="handleReviewVisible" size="small" :lock-scroll="false">
            <el-form :model="reviewForm">
                <h2>是否审核通过当前单据？</h2>
                <el-form-item label="审核意见" :label-width="formLabelWidth">
                    <el-input type="textarea"  :rows="3" placeholder="请输入内容" v-model="reviewForm.textarea">
                    </el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="reviewPlan(true)">审核通过</el-button>
                <el-button @click="reviewPlan(false)">审核不通过</el-button>
            </div>
        </el-dialog>-->
        <!-- 点击审批 审批弹窗 
        <el-dialog id="approvalMask" title="审批提示信息" :visible.sync="handleApprovalVisible" size="small" :lock-scroll="false">
            <el-form :model="approvalForm">
                <h2>是否审批通过当前单据？</h2>
                <el-form-item label="审批意见" :label-width="formLabelWidth">
                    <el-input type="textarea"  :rows="3" placeholder="请输入内容" v-model="approvalForm.textarea">
                    </el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="approvePlan(true)">审批通过</el-button>
                <el-button @click="approvePlan(false)">审批不通过</el-button>
            </div>
        </el-dialog>-->
    </div>
</template>

<script>
    export default {
        data(){
            return{
                pickerOptions: {     //期望到货时间不得早于当天
                    disabledDate(time) {
                        return time.getTime() < Date.now() - 8.64e7;
                    }
                },
                labelWidth:"80px",
                modifyForm:{
                    planCode:'',
                    planId:'',
                    legalPersonName:'',
                    legalPersonId:'',
                    creatorName:'',
                    createTime:'',
                    totalCount:'',
                    total:'',
                    source:'',
                    currencyCode:'',
                    currencyCodeWord:'',
                    status:''
                },
                legalPersonLists:[],   //法人名称下拉列表中的值
                sourceLists:[],   //计划来源下拉列表的值
                currencyCodeLists:[],   //计划币别下拉列表的值
                materialSubclassLists:[],   //计划明细 查询条件 备件状态
                modifyDetail:{
                    materialCode:'',
                    materialSubclass:''
                },
                pageIndex: 1,    //当前页（必传）
                pageSize: 10,   //每页多少条
                totalNumber: 20,
                totalPage: 2,
                currentPage3: 3,
                
                tableData:[],
                seedTableData:[],
                planItems:[],   //修改页面保存计划  计划行项目数组
                isPagingSpare:false,
                chooseSpare:{
                    code:'',
                    name:''
                },
                dialogFormVisible: false,
                // isPaging:false,
                loading:false,
                sparePageIndex: 1,    //当前页（必传）
                sparePageSize: 10,   //每页多少条
                spareTotalNumber: 20,
                spareTotalPage: 2,
                spareCurrentPage3: 3,
                planDetailsData:[],
                spareListDate:[],
                selectedSpareList:[],     // 选中的备件
                selSpare:[],//备件已选

                // handleReviewVisible:false,    //审核弹窗
                // reviewForm:{      //审核内容
                //     textarea:""
                // },
                // handleApprovalVisible:false,    // 审批弹窗
                // approvalForm:{      //审批内容
                //     textarea:""
                // },
                // formLabelWidth:"90",
                delFlag:false,     // 没点删除按钮
                //查询禁用
                selectDisabled:false,
                select2Disabled:false,
                
                tableDelete:[]

            }
        },
        mounted:function(){
            var _this=this;
            _this.$store.commit('currentActive', 'ChangePlan');
            // //ajax前后查询按钮禁用
            // $(".selectAll").ajaxStart(function(){
            //     _this.selectDisabled=true;
            // });
            // $(".selectAll").ajaxStop(function(){
            //     _this.selectDisabled=false;
            // });
            _this.modifyForm.planId=_this.$route.query.planId;        //?
            _this.modifyForm.status=_this.$route.query.status;
            _this.planSCDropDownValue();   //计划明细  计划来源和计划明细 下拉列表
            _this.legalPersonDropDownValue(); //计划明细  法人名称 下拉列表
            setTimeout(function(){
                _this.checkTheDetails();// 查询计划明细 _this.pageIndex,_this.pageSize
                _this.planItemDetaisFrom();//页面一打开  获取当前计划的计划明细  form表单 
            },0);
        },
        methods:{
            // 查询条件 法人名称 下拉列表的值
            legalPersonDropDownValue(){  //法人名称下拉列表值
                var _this = this;
                $.ajax({
                    type:'GET',
                    url:_this.procurement_service+"legalPerson/ofCurrentUser",
                    cache:false,
                    success:function(data){
                        if(data.success){
                            _this.legalPersonLists = data.data;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            // 下拉列表选择法人名称
            selectLegalPersonName(){
                var _this=this;
                for(var i=0;i<_this.legalPersonLists.length;i++){
                    if(_this.modifyForm.legalPersonName==_this.legalPersonLists[i].legalPersonName){
                        _this.modifyForm.legalPersonId=_this.legalPersonLists[i].id;
                    }
                }
            },
            //  计划明细  计划来源和计划明细 下拉列表
            planSCDropDownValue(){
                var _this=this;
                var tmp = ["source","currencyCode"];
                $.ajax({
                    type:'POST',
                    url:_this.procurement_service+'procurement/getPullDownList',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",     //*****
                    success:function(data){
                        if(data.success){
                            // console.log(data.data);
                            _this.sourceLists = data.data.source;
                            _this.currencyCodeLists = data.data.currencyCode;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            // 下拉列表选择币别
            selectCurrencyCode(){
                var _this=this;
                // 表格中的币别显示汉字
                for(var i=0;i<_this.currencyCodeLists.length;i++){
                    if(_this.modifyForm.currencyCode == _this.currencyCodeLists[i].value){
                        _this.modifyForm.currencyCodeWord = _this.currencyCodeLists[i].label;
                    }
                }
                for(var i=0;i<_this.tableData.length;i++){
                    _this.tableData[i].currencyCode=_this.modifyForm.currencyCode;
                    _this.tableData[i].currencyCodeWord=_this.modifyForm.currencyCodeWord;
                }
            },
            // 页面一打开  获取当前计划的计划明细  form表单
            planItemDetaisFrom(){
                var _this=this;
                var tmp = {planId:_this.modifyForm.planId,pageIndex:_this.pageIndex,pageSize:_this.pageSize};
                $.ajax({
                    type: 'POST',
                    url: _this.procurement_service+"plan/queryPlan",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",     //*****
                    success: function (data) {
                        if (data.success) {
                            _this.isPaging=true;
                            // console.log(data.data);
                            data.data.dataList[0].total=data.data.dataList[0].total.toFixed(2);
                            _this.modifyForm=data.data.dataList[0];  
                            _this.modifyForm.legalPersonId=data.data.dataList[0].legalPersonId;

                            for(var i=0;i<_this.legalPersonLists.length;i++){
                                if(_this.modifyForm.legalPersonId==_this.legalPersonLists[i].id){
                                    _this.modifyForm.legalPersonName=_this.legalPersonLists[i].legalPersonName;
                                }
                            }
                            _this.selectMaterialSubclassDropDownValue();  // 计划明 备件分类下拉列表的值
                        }else
                            // console.log(data.errorMessage);                             
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },
            // 计划明细 查询条件 备件分类下拉列表
            selectMaterialSubclassDropDownValue(){
                var _this = this;
                $.ajax({
                    type:'GET',
                    url:_this.procurement_service+"plan/selectMaterialSubclass?planId="+_this.modifyForm.planId,
                    cache:false,
                    success:function(data){
                        if(data.success){
                            _this.materialSubclassLists = data.data;
                            // console.log(_this.materialSubclassLists);
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            // 查询计划明细 pageIndex,pageSize ,pageIndex:pageIndex,pageSize:pageSize
            checkTheDetails(){
                var _this=this;
                _this.checkTheDetailsVisible=true;
                var tmp = {planId:_this.modifyForm.planId,materialCode:_this.modifyDetail.materialCode, materialSubclass:_this.modifyDetail.materialSubclass};
                _this.selectDisabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.procurement_service+"plan/queryPlanItem",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",     //*****
                    success: function (data) {
                        if (data.success) {
                            // console.log(data.data);
                            var arr=data.data.dataList;
                            //金额保留两位
                            for(var i=0;i<arr.length;i++){
                                arr[i].price=arr[i].price.toFixed(2);
                                arr[i].amount=arr[i].amount.toFixed(2);
                            }
                            _this.tableData=arr;
                            // _this.totalNumber=data.data.totalNumber;    //总条数
                            // _this.totalPage=data.totalPage;    //总页数 
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }                             
                        _this.selectDisabled=false;
                    }
                });

            },
            // 删除
            handleDelete(index, row) {
                var _this=this;
                _this.delFlag=true;
                _this.seedTableData=_this.tableData; 
                console.log(_this.tableData);
                if(row.planItemId){
                    row.removed=true;
                     // 删除已有的计划明细----ok
                    _this.tableData=[];
                    for(var i=0;i<_this.seedTableData.length;i++){
                        if(!_this.seedTableData[i].removed){
                            _this.tableData.push(_this.seedTableData[i]);
                        }else{
                            _this.tableDelete.push({planItemId:_this.seedTableData[i].planItemId});
                        }
                    }

                }else{
                    // 新增计划明细，但未保存---ok
                    var tmpTableData=[];
                    for(var i=0;i<_this.tableData.length;i++){
                        if(_this.tableData[i].materialCode!=row.materialCode){
                            tmpTableData.push(_this.tableData[i]);
                        }
                    }
                    _this.tableData=tmpTableData;
                }
            },
            // 新增按钮   新增计划明细------打开选择备件的弹窗
            // 选择备件 /material/search 
            modifyFormDetais(sparePageIndex,sparePageSize){
                var _this=this;
                // //ajax前后查询按钮禁用
                // $(".selectAll").ajaxStart(function(){
                //     _this.selectDisabled=true;
                // });
                // $(".selectAll").ajaxStop(function(){
                //     _this.selectDisabled=false;
                // });
                _this.dialogFormVisible = true;
                _this.loading=true;
                _this.spareListDate=[];   //备件列表为空
                var tmp={code:_this.chooseSpare.code,name:_this.chooseSpare.name,pageIndex:sparePageIndex,pageSize :sparePageSize};
                _this.select2Disabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service+"material/searchEnabled",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",     //*****
                    success: function (data) {
                        if (data.success) {
                            _this.loading=false;
                            _this.isPagingSpare=true; 
                            _this.spareListDate=data.data.materialList; 
                            _this.spareTotalNumber=data.data.totalNumber;    //总条数
                            _this.spareTotalPage=data.totalPage;    //总页数
                            _this.selectedSpareList=[];   // 打开弹窗选中的清空
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }                            
                        _this.select2Disabled=false;      
                    }
                });
            },
            //新增弹窗中的确定按钮   选择备件
            selectSpare(index,row){    //选中
                var _this=this;
                for(var i=0;i<_this.tableData.length;i++){
                    if(row.code==_this.tableData[i].materialCode){
                        //将备件已选的记录下来
                        _this.selSpare.push(row.code);
                        return;
                    }
                }
                if(row.checked){
                    _this.selectedSpareList.push({"id":row.id,"subclass":row.subclassName,"materialName":row.name,"materialCode":row.code,"standard":row.standard,"unit":row.unit});
                }else{
                    _this.selectedSpareList.push({"id":row.id,"subclass":row.subclassName,"materialName":row.name,"materialCode":row.code,"standard":row.standard,"unit":row.unit});
                }
            },

            insertMateraialSupplier(){   //选择备件弹窗  确定按钮  确定新增计划明细
                var _this=this;
                _this.dialogFormVisible = false;
                if(_this.selSpare.length!=0){
                    var selSpare=_this.selSpare.join(",");
                    _this.common.errorTip("备件"+selSpare+"已选")
                } 
                for(var i=0;i<_this.selectedSpareList.length;i++){
                    _this.tableData.push({
                        materialSubclass:_this.selectedSpareList[i].subclass,
                        materialCode:_this.selectedSpareList[i].materialCode,
                        materialName:_this.selectedSpareList[i].materialName,
                        standard:_this.selectedSpareList[i].standard,
                        unit:_this.selectedSpareList[i].unit,
                        deliveryTimeExpectation:"",
                        quantity:0,
                        currencyCode:_this.modifyForm.currencyCode,
                        currencyCodeWord:_this.modifyForm.currencyCodeWord,
                        price:0,
                        removed:false
                    });
                }
            },
            // //   选择备件弹窗 分页
            spareSizeChange(val) {
                // console.log(`每页 ${val} 条`);
                var _this = this;
                _this.sparePageSize=val;
                _this.modifyFormDetais(_this.sparePageIndex, _this.sparePageSize);
            },
            // //选择备件弹窗  点击页码分页查询点击事件
            spareCurrentChange(val) {
                // console.log(`当前页: ${val}`);
                var _this = this;
                _this.sparePageIndex=val;
                _this.modifyFormDetais(_this.sparePageIndex, _this.sparePageSize);
            },
            // 输入计划数量
            planQuantity(index,row){
                var _this=this;
                row.amount=row.price * row.quantity;
                _this.modifyForm.totalCount=0;
                _this.modifyForm.total=0;
                setTimeout(function(){
                     for(var i=0;i<_this.tableData.length;i++){
                        _this.modifyForm.totalCount +=_this.tableData[i].quantity;
                        _this.modifyForm.total +=_this.tableData[i].price * _this.tableData[i].quantity;
                    }
                },0);
            },
            // 输入单价
            planPrice(index,row,event){
                var _this=this;
                if(row.price){
                    row.price=parseFloat(row.price.toFixed(2));   //输入的单价最多只能有两位小数
                }
                row.amount=row.price * row.quantity;
                row.amount=parseFloat(row.amount.toFixed(2));   // 金额最多只能有两位小数
                _this.modifyForm.totalCount=0;
                _this.modifyForm.total=0;
                setTimeout(function(){
                    for(var i=0;i<_this.tableData.length;i++){
                        _this.modifyForm.totalCount +=_this.tableData[i].quantity;
                        _this.modifyForm.total +=_this.tableData[i].price * _this.tableData[i].quantity;
                    }
                    _this.modifyForm.total=_this.modifyForm.total.toFixed(2);
                },0); 
            },
            // 选择期望到货日期 格式化
            selectedDeliveryTimeExpectation(index,row){
                var _this=this;
                row.deliveryTimeExpectation=moment(row.deliveryTimeExpectation).format("YYYY-MM-DD");
            },
            // 修改计划的保存
            savePlan(){
                var _this = this;
                _this.saveOld();
            },
            // 修改的保存
            saveOld(){
                var _this=this;
                var tmp = {legalPersonId:_this.modifyForm.legalPersonId,planId:_this.modifyForm.planId,currencyCode:_this.modifyForm.currencyCode,status:_this.modifyForm.status,planItems:_this.tableData,deletePlanItems:_this.tableDelete};
                if(_this.tableData.length!=0){
                   $.ajax({
                       type: 'POST',
                       url: _this.procurement_service+"plan/update",
                       cache: false,
                       data:JSON.stringify(tmp),
                       dataType:'JSON',
                       contentType: "application/json;charset=utf-8",     //*****
                       success: function (data) {
                           if (data.success) {
                               _this.tableData=data.data.planItems;
                               _this.delFlag=false;
                               //输入的金额保留两位
                               for(var i=0;i<_this.tableData.length;i++){
                                   _this.tableData[i].price=Number(_this.tableData[i].price).toFixed(2);
                                   _this.tableData[i].amount=Number(_this.tableData[i].amount).toFixed(2);
                               }
                               _this.common.successTip("保存成功！");
                           }else
                               _this.common.errorTip(data.errorMessage);
                       }
                   });
               }else{
                   _this.common.errorTip("计划明细不能为空！");
               }
            },
            // 修改计划 提交计划
            submitPlan(){
                var _this = this; 
                _this.submitOld();
                // for(var i=0;i<_this.tableData.length;i++){
                //     _this.planItems.push({
                //         planItemId:_this.tableData[i].planItemId,
                //         materialCode:_this.tableData[i].materialCode,
                //         quantity:_this.tableData[i].quantity,
                //         deliveryTimeExpectation:_this.tableData[i].deliveryTimeExpectation,
                //         price:_this.tableData[i].price,
                //         removed:_this.tableData[i].removed,
                //         remark:_this.tableData[i].remark
                //     });
                // }
                // var tmp = {planId:_this.modifyForm.planId,source:_this.modifyForm.source,currencyCode:_this.modifyForm.currencyCode,legalPersonId:_this.modifyForm.legalPersonId,planItems:_this.planItems};
                // $.ajax({
                //     type: 'POST',
                //     url: _this.procurement_service+"plan/commit",
                //     cache: false,
                //     data:JSON.stringify(tmp),
                //     dataType:'JSON',
                //     contentType: "application/json;charset=utf-8",     //*****
                //     success: function (data) {
                //         if (data.success) {
                //             // console.log(data.data);
                //             _this.common.successTip("提交成功！");
                //             _this.$router.push("/SparePlan");
                //         }else
                //             // console.log(data.errorMessage);                             
                //             _this.common.errorTip(data.errorMessage);
                //     }
                // });
            },
            // 修改的提交 submitOld
            submitOld(){
                var _this=this;
                // if(_this.delFlag){
                //     _this.tableData=_this.seedTableData;
                // }
                // var tableDelete=[];
                // var tableSave=[];
                // for(var i in _this.tableData){
                //     if(_this.tableData[i].removed){
                //         //放删除的
                //         tableDelete.push({planItemId:_this.tableData[i].planItemId});
                //     }else{
                //         tableSave.push(_this.tableData[i]);
                //     }
                // }
                var tmp = {legalPersonId:_this.modifyForm.legalPersonId,planId:_this.modifyForm.planId,currencyCode:_this.modifyForm.currencyCode,status:_this.modifyForm.status,planItems:_this.tableData,deletePlanItems:_this.tableDelete};
               if(_this.tableData.length!=0){
                   $.ajax({
                       type: 'POST',
                       url: _this.procurement_service+"plan/submitOld",
                       cache: false,
                       data:JSON.stringify(tmp),
                       dataType:'JSON',
                       contentType: "application/json;charset=utf-8",     //*****
                       success: function (data) {
                           if (data.success) {
                               _this.common.successTip("提交成功！");
                               _this.$router.push("/SparePlan");
                               _this.delFlag=false;
                           }else
                           // console.log(data.errorMessage);
                               _this.common.errorTip(data.errorMessage);
                       }
                   });
               }else{
                   _this.common.errorTip("不可以删除为空");
               }

            },
            // // 修改计划 审核弹窗
            // handleReview(){
            //     var _this=this;
            //     _this.handleReviewVisible=true;
            // },
            // // 修改计划 审核通过
            // reviewPlan(reviewStatus){
            //     var _this = this;
            //     var tmp = {planId:_this.modifyForm.planId,reviewStatus:reviewStatus};
            //     $.ajax({
            //         type: 'POST',
            //         url: _this.procurement_service+"plan/review",
            //         cache: false,
            //         data:JSON.stringify(tmp),
            //         dataType:'JSON',
            //         contentType: "application/json;charset=utf-8", 
            //         success: function (data) {
            //             if (data.success) {
            //                 // console.log(data.data);
            //                 _this.common.successTip("操作成功！");
            //                 _this.handleReviewVisible=false;
            //                 _this.$router.push("/SparePlan");
            //             }else
            //                 // console.log(data.errorMessage);  
            //                 _this.common.errorTip(data.errorMessage);
            //         }
            //     });
            // },
            // // 修改计划 审批弹窗
            // handleApprove(){
            //     var _this=this;
            //     _this.handleApprovalVisible=true;
            // },
            // // 修改计划 审批
            // approvePlan(approveStatus){
            //     var _this = this;
            //     var tmp = {planId:_this.modifyForm.planId,approveStatus:approveStatus};
            //     $.ajax({
            //         type: 'POST',
            //         url: _this.procurement_service+"plan/approve",
            //         cache: false,
            //         data:JSON.stringify(tmp),
            //         dataType:'JSON',
            //         contentType: "application/json;charset=utf-8", 
            //         success: function (data) {
            //             if (data.success) {
            //                 // console.log(data.data);
            //                 _this.common.successTip("操作成功！");
            //                 _this.handleApprovalVisible=false;
            //                 _this.$router.push("/SparePlan");
            //             }else
            //                 // console.log(data.errorMessage);  
            //                 _this.common.errorTip(data.errorMessage);
            //         }
            //     });
            // },
            //  // ===================================
            // successTip(p) {     //成功时的提示信息
            //     this.$notify({
            //         title: '成功',
            //         message: p,
            //         type: 'success'
            //     });
            // },
            // errorTip(p) {     //错误提示
            //     this.$notify.error({
            //         title: '错误',
            //         message: p
            //     });
            // }
        }
    }
</script>

<style>

</style>